<template>
	<view >
    <my-serch :bgc="'#c00000'" :radius="80"></my-serch>
    <view class="cart">
      <scroll-view scroll-y="true" class="left" :style="{height:height + 'px'}" :show-scrollbar="false" :enhanced="true">
        <view :class="['left-scroll-item', index === active ? 'active': '']" v-for="(item,index) in cateList" :key="index" @click="changeActive(index)">
          {{item.cat_name}}
        </view>
      </scroll-view>
      <!-- 右侧滚动 -->
      <scroll-view scroll-y="true" class="right" :style="{height:height + 'px'}" :scroll-top="scorllTop">
        <view   v-for="(i,m) in cateList2" :key="m">
          <view class="right-title">/{{i.cat_name}}/</view>
          <view class="right-list">
            <view class="cata-list3" v-for="(i2, m2) in i.children " :key="m2" @click="pushList(i2.cat_id)">
                <image :src="i2.cat_icon"></image>
                <text>{{i2.cat_name}}</text>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
  // import requset from '../../until/request.js'
  // import mySerchh from '../../components/my-serch/my-serch.vue'
  import tabBarSet from '@/mixins/tabBarSet.js'
	export default {
    mixins:[tabBarSet], // 执行mixin里面的代码，设置购物车总数
		data() {
			return {
				height : 0, // 计算高度
        cateList: [] ,// 左边选项 一级分类
        cateList2 : [] ,// 二级分类
        active: 0, // 选中项
        scorllTop: 0
			}
		},
    onLoad() {
      // console.log(requset);
      // windowHeight 可使用窗口宽度，单位px
      this.height = uni.getSystemInfoSync().windowHeight - 50// 获取屏幕的可用高度,再减去serch搜索框的高度50
      this.getCateList()
    },
    methods:{
      async getCateList ()  {
        const { data } = await uni.$http.get('/api/public/v1/categories')
        this.cateList = data.message
        this.cateList2 = this.cateList[0].children
        // requset('GET', '/api/public/v1/categories', null, function(data) {
        //   console.log(data)
        // })
      },
      changeActive (index) {
         this.active = index
         this.cateList2 = this.cateList[index].children // 改变一级分类对象的二级数组
         this.scorllTop = this.scorllTop === 0 ? 1 : 0
      },
      pushList (id) {
        uni.navigateTo({
          url:'../../subpkg/goods_list/goods_list?id=' + id
        })
      }
    }
	}
</script>

<style lang="scss">
.cart {
  display: flex;
  height: 100%;
  .left{
    // height: 100%;
    width: 300rpx;
     .left-scroll-item {
      width: 120px;
      line-height: 60px;
      background-color: #f7f7f7;
      text-align: center;
      font-size: 12px;
     }
  }
  // 激活项的样式
        .active {
          background-color: #ffffff!important;
          position: relative;
  
          // 渲染激活项左侧的红色指示边线
          &::before {
            content: ' ';
            display: block;
            width: 3px;
            height: 30px;
            background-color: #c00000;
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
          }
          }
     .right-title {
         font-size: 12px;
         font-weight: bold;
         text-align: center;
         padding: 15px 0;
     }
     .right-list {
       display: flex;
       flex-wrap: wrap;
       .cata-list3 {
         width: 33.3%;
         // margin: 0 1rpx;
         margin-bottom: 5rpx;
         display: flex;
         flex-direction: column;
         justify-content: center;
         align-items: center;
         image {
          width: 60px;
          height: 60px;
         }
       }
     }
}
</style>
